package com.monika.main.security.handler;

import com.alibaba.fastjson2.JSON;
import com.monika.main.system.domain.AjaxResult;
import com.monika.main.system.util.ServletUtil;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Author whh
 * Date 2023/04/22/ 17:45
 * <p></p>
 */
@Component
public class PrimalAccessDeniedHandler implements AccessDeniedHandler {

    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {

        String msg = String.format("权限不足，无法访问系统资源%s", request.getRequestURI());
        ServletUtil.renderString(response, AjaxResult.fail(msg).ajaxResultJson());
    }
}
